requirejs.config({
    baseUrl: '../js/libs',
    paths: {
        jquery: 'jquery.min',
        jquery_ext: 'jquery.ext',
        jquerycookie: 'jquery.cookie',
        md5: 'md5.min',
		config : "../common/config",
        layer: '../plugins/layer/layer'
    },
    shim: {
    	jquery: {
    	  exports: '$'
    	},
    	jquery_ext:['jquery'],
    	'layer': ['jquery']
    }
});
require(['jquery','jquery_ext','md5','config','jquerycookie','layer'], function($,jqext,md5,config) {
	//加载扩展模块
    layer.config({
		extend: '../plugins/layer/extend/layer.ext.js'
	});
	window.layer = layer;
	var _href=location.href;
	var _dhref=decodeURIComponent(_href);
	if(_dhref.indexOf('\'')!=-1||_dhref.indexOf('\"')!=-1||_dhref.indexOf('>')!=-1||_dhref.indexOf('<')!=-1){
		layer.alert("URL地址存在非法字符 ( '  \"  >  < ) :  \r\n"+_href);
		return;
	}
	
	var Login = {};
	
	/**
	 * 登录
	 */
	Login.login = function($loginNode){
		var params={};
		if($loginNode != null && typeof $loginNode != 'undefined'){
			var userName=$($loginNode).find('input[name=userName]');
			if(userName.length>0){
				params.usercode=$.trim(userName.val());
			}
			var password=$($loginNode).find('input[name=password]');
			if(password.length>0){
				params.passwd=md5($.trim(password.val()));
			}
		}
		//设置请求随机数
		params._r=Math.random();
		$.ajax({
			url: config.apiRoot()+'/auth/login',
			type: 'POST',
			data: config.setFullParameter(params),
			dataType: 'jsonp',
			cache: 'false',
			success: function($resultdata) {
				console.info($resultdata);
				console.info($resultdata.code);
				if($resultdata!=null){
					if($resultdata.code=='200'){
						//登录成功
						// 登录成功 返回登录前url
						//$.cookie("token", $resultdata.data);
						var _rtourl = $.urlparameter('url');
						//只重定向本站地址
						if (_rtourl != null && decodeURIComponent(_rtourl).indexOf(location.protocol+'//'+location.hostname)==0) {
							window.location.href = _rtourl;
						}else{
							window.location.href = "index.html";
						}
					}else{//未定义业务接收 方法
						layer.alert(rep_businessNo($resultdata.businessMsg.businessNote));
					}
				}
			},
			error: function(jqXHR, textStatus, errorThrown) {
				//TODO:提示消息
				layer.alert("登录失败!");
				//_log("请求错误:"+JSON.stringify(jqXHR) + "," + textStatus + "," + errorThrown);
			}
		});
	};
	window.login=Login.login;

	$(function(){
		$("body").keydown(function(event){
			//按enter键登录
			 if (event.keyCode==13){
				 $("#btn-login").click();
			 }
		});
	});

});